<script type="text/ecmascript-6">
  import Navbar from '../../components/base/navbar.vue';
  export default{
      name:"coach_rewards_points",
      components:{
          Navbar
      },
      data(){
          return {
              myID:this.$route.params.id,
              listChecked:[]
          }
      },
      created(){
          EventBus.$on("reward-complete",this.rewardComplete);
          this.$store.dispatch("querySignList",this.myID);
      },
      computed:{
          list:{
              get(){
                  return this.$store.getters.getSignList
              }
          },
          isReward: function() {
            if( !this.list.signed ) return false;

            let len_unrewarded = 0;
            this.list.signed.forEach( v => {
              if( v.rewarded==0 ){
                len_unrewarded +=1;
              }
            });
            if( len_unrewarded==0 ) return true;
          }
      },
      beforeDestroy(){
        EventBus.$off("reward-complete");
      },
      methods:{
         reward(){
             console.log(this.listChecked);
           if(this.listChecked.length==0){
             this.$Modal.info({title:"消息提示",body:'请先选择要奖励积分的会员！'});
             return;
           }
           this.$Prompt.info({title:"消息提示",spec:"奖励人数："+this.listChecked.length,validator(v) {
             if (/^[1-9]$|^[1-9]\d$|^1\d{2}$|^200$/.test(v)) {
               return true;
             } else {
               return `[${v}]不满足输入条件`;
             }
           },onOk:(v)=>{
             let user_ids = [];
             this.listChecked.forEach(v => user_ids.push(v.user_id));
//             console.log(user_ids);
             this.$store.dispatch("submitreward",{id:this.myID,user_ids:user_ids,reward_value:v});
           }});
         },
         rewardComplete(){
            this.$Modal.info({title:"消息提示",body:"积分奖励申请已提交",okText:"完成",cancelText:"继续奖励",onOk:()=>{
              this.listChecked=[];
              this.$store.dispatch("querySignList",this.myID);
            },onCancel:()=>{
              window.history.back();
            }});
         }
      }
  }
</script>
